<template>
  <div id="popupbody" v-if="dialogVisible">
    <div class="popupbody-box">
      <div class="popupbody-title">
        <span>选择职工用户</span>
        <span class="el-icon-close" @click="closePOpup"></span>
      </div>
      <div class="popupbody-boxin" style="padding:10px;">
        <!--      搜索组件-->
        <SearchModle dataKey="MultipleteacherModle" @searchFn="searchFn"></SearchModle>
        <!--      end -->
        <el-table :data="arryList"
                  height="400"
                  :stripe="tableStyle.tableStripe"
                  :border="tableStyle.tableBorder"
                  tooltip-effect="dark"
                  @row-click="rowClick"
                  ref="table">
          <el-table-column width="100"  align="center">
            <template slot-scope="scope">
              <el-radio v-model="radio" :label="scope.row.id" class="radioCheckBox">{{ scope.row.id }}</el-radio>
            </template>
          </el-table-column>
          <el-table-column label="头像"align="center">
            <template slot-scope="scope">
              <ImagePreview :src="scope.row.pic" width="40px" height="40px"></ImagePreview>
            </template>
          </el-table-column>
          <el-table-column label="姓名" prop="realname" align="center"></el-table-column>
          <el-table-column label="班级" align="center">
            <template slot-scope="scope">
              {{ scope.row.classes ? scope.row.classes.class_name : '' }}
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
            background
            layout="prev, pager, next"
            :current-page="page.pageindex"
            :total="page.total"
            :page-size="page.pagesize"
            @current-change="handleSizeChange">
        </el-pagination>
      </div>
      <div class="popupbody-footer">
        <el-button size="small" @click="closePOpup">返回</el-button>
        <el-button type="primary" size="small" @click="submitFormAdd()">确认并保存</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js'

export default {
  name: 'studentMultiple',
  props: ['visible', 'dynamicTagsArray'],
  data() {
    return {
      radio: '',
      dialogVisible: this.visible,
      // 设置table样式
      tableStyle: tableoption,
      // 设置table页面分页所需
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      arryList: [],
      applyBookBox: {}, // 选中人员信息
      applyBookBoxInit: {}, // 本页面对应对象
      // 搜索
      searchForm: {}
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        if(this.dynamicTagsArray && JSON.stringify(this.dynamicTagsArray)!=='{}'){
          this.applyBookBox = this.getJson(this.dynamicTagsArray)
          this.applyBookBoxInit[this.dynamicTagsArray.id] = this.getJson(this.dynamicTagsArray)
          this.radio = this.dynamicTagsArray.id
        }
        this.InitFn()
      }
    }
  },
  created() {
    this.InitFn()
  },
  methods: {
    // 初始化
    async InitFn() {
      this.searchForm.p = this.page.pageindex
      let data = await this.$fetch(this.api.admin_user_index, this.searchForm)
      this.arryList = data.list.data;
      this.page.total = data.list.total;
    },
    // 搜索
    searchFn(option) {
      this.page.pageindex = 1
      this.searchForm = option
      this.InitFn()
    },
    // 行选中
    rowClick(option) {
      this.applyBookBox = option.name
      this.radio = option.id
      this.applyBox = option
    },
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    // 提交数据
    async submitFormAdd() {
      this.$emit('studentFn', this.applyBox)
      this.closePOpup()
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option){
      return JSON.parse(JSON.stringify(option))
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#popupbody{
  z-index: 9999;
}
.popupbody-boxin {
  min-width: 700px;
}
</style>
